/*
 * Copyright (C) 2013. Young,Fey <fey.young@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.youngfey.util

import org.junit.*
import static org.junit.Assert.*

/**
 *
 * @author Young , Fey <fey.young@gmail.com>
 * @version 0.1.d
 * Created at 2013-04-24 22:21
 */
class ConfigurationTest {
    @Before
    void setUp() {
        def here = new File('here.prop')
        here.delete()
        assertFalse here.exists()
    }

    @Test
    void testSaveAndLoad() {
        def conf = Configuration.getInstanceHere('here.prop')
        conf.set 'name', 'Hiarcs'
        conf.set 'age', 18
        conf.set 'gf', 'Nil'
        conf.set 'whatever', 'a!@#$()_":="\\//d'
        conf.save()

        def conf2 = Configuration.getInstanceHere('here.prop')
        assertEquals('18', conf2.get('age'))
        assertEquals(18, conf2.getInteger('age'))
        conf2.set('gf', null)
        assertNull(conf2.get('gf'))
    }

    @Test
    void testBatchLoad() {
        def confs = Configuration.getInstances(System.getProperty('user.dir'), ~/.*\.bp/)
        assertEquals(3, confs.size())
        assertEquals('18', confs[2].get('age'))
    }
}